﻿package com.yf.weibofans.copyright
{
	import flash.ui.*;
	import flash.display.*;
	import flash.net.*;
	import flash.events.ContextMenuEvent;

	public class Copyright
	{
		private var myName:String;
		private var myUrl:String;
		private var target:InteractiveObject;
		private var itemEnabled:Boolean;

		public function Copyright(target:InteractiveObject, _name:String, _itemEnabled:Boolean = false, _url:String = "")
		{
			myName = _name;
			myUrl = _url;
			itemEnabled = _itemEnabled;

			this.target = target;
			this.removeAndAddItem();
		}

		private function removeAndAddItem():void
		{
			var myContextMenu:ContextMenu=new ContextMenu();
			var item:ContextMenuItem = new ContextMenuItem(myName);
			myContextMenu.hideBuiltInItems();
			myContextMenu.customItems.push(item);
			target.contextMenu = myContextMenu;
			item.enabled = itemEnabled;
			if (itemEnabled)
			{
				item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemSelectHandler);
			}
		}

		private function itemSelectHandler(e:ContextMenuEvent):void
		{
			navigateToURL(new URLRequest(myUrl), "_blank");
		}
	}
}